package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
)

/**
   抽象的封装
 */


type BaseController struct {
	beego.Controller

}

type MessageResult struct {
	Code int			`json:"code"`
	Message string		`json:"message"`
	Data interface{}	`json:"data"`
}

// 参数非空校验
func (base *BaseController) paramsCheck(strParams ...string) bool{
	for _,param :=range strParams {
		if param=="" {
			return false
		}
	}
	return true
}


func (base *BaseController) resultOk(){
	result:=MessageResult{
		Code: 0,
		Message: "success",
		Data:nil,
	}
	base.Data["json"] = result
	base.ServeJSON()
}

func (base *BaseController) resultOkData(data interface{}){
	result:=MessageResult{
		Code: 0,
		Message: "success",
		Data:data,
	}
	base.Data["json"] = result
	base.ServeJSON()
}


func (base *BaseController) resultError(message string){
	result:=MessageResult{
		Code: -1,
		Message: message,
		Data:"",
	}
	base.Data["json"] = result
	base.ServeJSON()
}